using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using TnPlus.Entities.Models;
using TnPlus.Entities.Utils;
using TnPlus.Common;

namespace TnPlus.DAL.Base
{
	public class AcctListNotSendMessageDAOBase
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors

		public AcctListNotSendMessageDAOBase(string connectionStringName)
		{
			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the AcctListNotSendMessage table.
		/// </summary>
		public virtual void Insert(AcctListNotSendMessageInfo acctListNotSendMessageInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AccountNo", acctListNotSendMessageInfo.AccountNo),
				new SqlParameter("@Description", acctListNotSendMessageInfo.Description)
			};

			SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "AcctListNotSendMessage_Insert", parameters);
		}

		/// <summary>
		/// Updates a record in the AcctListNotSendMessage table.
		/// </summary>
		public virtual void Update(AcctListNotSendMessageInfo acctListNotSendMessageInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AccountNo", acctListNotSendMessageInfo.AccountNo),
				new SqlParameter("@Description", acctListNotSendMessageInfo.Description)
			};

			SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "AcctListNotSendMessage_Update", parameters);
		}

		/// <summary>
		/// Deletes a record from the AcctListNotSendMessage table by its primary key.
		/// </summary>
		public virtual void Delete(string accountNo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AccountNo", accountNo)
			};

			SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "AcctListNotSendMessage_Delete", parameters);
		}

		/// <summary>
		/// Selects a single record from the AcctListNotSendMessage table.
		/// </summary>
		public virtual AcctListNotSendMessageInfo Select(string accountNo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AccountNo", accountNo)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "AcctListNotSendMessage_Select", parameters))
			{
				if (dataReader.Read())
				{
					return MakeAcctListNotSendMessageInfo(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the AcctListNotSendMessage table.
		/// </summary>
		public List<AcctListNotSendMessageInfo> SelectAll()
		{
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "AcctListNotSendMessage_SelectAll"))
			{
				List<AcctListNotSendMessageInfo> acctListNotSendMessageInfoList = new List<AcctListNotSendMessageInfo>();
				while (dataReader.Read())
				{
					acctListNotSendMessageInfoList.Add(MakeAcctListNotSendMessageInfo(dataReader));
				}

				return acctListNotSendMessageInfoList;
			}
		}

		/// <summary>
		/// Creates a new instance of the AcctListNotSendMessage class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected virtual AcctListNotSendMessageInfo MakeAcctListNotSendMessageInfo(SqlDataReader dataReader)
		{
			AcctListNotSendMessageInfo acctListNotSendMessageInfo = new AcctListNotSendMessageInfo();
			acctListNotSendMessageInfo.AccountNo = SqlClientUtility.GetString(dataReader, DbConstants.ACCTLISTNOTSENDMESSAGE.ACCOUNTNO);
			acctListNotSendMessageInfo.Description = SqlClientUtility.GetString(dataReader, DbConstants.ACCTLISTNOTSENDMESSAGE.DESCRIPTION);

			return acctListNotSendMessageInfo;
		}

		#endregion
	}
}
